#include "xml_util.h"
#include "misc/strutil.h"

namespace renderit
{
	namespace messiah
	{
		void find_guid_in_path(tinyxml2::XMLElement * root_elem, const std::string& path, std::vector<guid_info>& result)
		{
			const char * tag = root_elem->Value();
			// Ignore <Uuid> ... </Uuid>
			if (std::string(tag) == "Uuid")
			{
				return;
			}

			const char * text = root_elem->GetText();
			if (text && strutil::str_is_guid(text))
			{
				guid_info gi;
				gi.guid = text;
				gi.path = path;
				gi.xml_elem_ = root_elem;
				//xml_guid_map_[gi.guid].push_back(gi);
				result.push_back(gi);
			}

			tinyxml2::XMLElement * first_child = root_elem->FirstChildElement(nullptr);
			while (first_child)
			{
				find_guid_in_path(first_child, path.length() > 0 ? path + "." + first_child->Value() : path + first_child->Value(), result);
				first_child = first_child->NextSiblingElement();
			}
		}
	}
}